package com.ayou.eggguard.farm.controller;

import com.ayou.common.utils.PageBean;
import com.ayou.common.utils.Result;
import com.ayou.eggguard.farm.pojo.Drug;
import com.ayou.eggguard.farm.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/drug")
public class DrugController {
    @Autowired
    private DrugService drugService;

    @GetMapping("/getDrugs")
    public Result<PageBean<Drug>> getDrugs(Integer pageNum,
                                           Integer pageSize,
                                           @RequestParam(required = false) String drugNumber){
        PageBean<Drug> pb=drugService.getDrugs(pageNum,pageSize,drugNumber);
        return Result.success(pb);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Drug drug){
        drugService.add(drug);
        return Result.success();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Drug drug){
        drugService.update(drug);
        return Result.success();
    }

    @GetMapping("/delete")
    public Result delete(Integer id){
        drugService.delete(id);
        return Result.success();
    }
}
